﻿/**
 * Copyright (c) 2008 michiyasu wada
 * http://www.seyself.com/
 * 
 * Distributed under The MIT License.
 * [http://www.opensource.org/licenses/mit-license.php]
 */

package demo.buttons 
{
import flash.display.DisplayObjectContainer;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.text.TextField;
import jp.progression.casts.CastButton;
import flash.display.MovieClip;
import demo.scenes.Main;
import jp.progression.commands.DoTweener;
import jp.progression.commands.ParallelList;


public class MenuItemButton extends CastButton
{
    
    public var data:XML;
    
    //--------------------------------------------------------------------------
    //  Constructor
    //--------------------------------------------------------------------------
    public function MenuItemButton( data:XML=null ) 
    {
        this.parallelMode = true;
        if(data) setup( data );
    }
    
    //--------------------------------------------------------------------------
    //  Override Methods
    //--------------------------------------------------------------------------
    override protected function _onCastAdded():void
    {
        var n:int = this.parent.getChildIndex( this );
        y = 150;
        x = n * 100;
        addCommand( new DoTweener( this, { y: 12, time: 0.6 } , n * 10 ));
    }
    
    override protected function _onCastRemoved():void
    {
        var n:int = this.parent.getChildIndex( this );
        addCommand(
            new DoTweener( this, { y: 150, time: 0.6 } , n * 3 )
        );
    }
    
    
    //--------------------------------------------------------------------------
    //  Private Methods
    //--------------------------------------------------------------------------
    private function setup( data:XML )
    {
        this.data = data;
        var image = getChildByName("ProductImage");
        
        // クリック時に移動する先のシーン識別子を指定します。
        //sceneId = new SceneId( "/index/contact" );
        
        if( data.Thumbnail.URL.toString().length ){
            var request:URLRequest = new URLRequest( data.Thumbnail.URL );
            var loader:Loader = new Loader();
            loader.load( request );
            image.addChild( loader );
            
            loader.x = (75 - data.Thumbnail.Width ) / 2 >> 0;
            loader.y = (75 - data.Thumbnail.Height) / 2 >> 0;
            getChildByName("NoImageIcon").visible = false;
        }
        
        // マウスオーバー時のツールチップ内容を指定します。
        toolTip.text = data.Title;
        
        
        var label = getChildByName("label");
        label.text = data.Title;
        
        //リンク先を指定
        this.href = data.DetailPageURL;
    }
    
}

}